package com.canbot.u05.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.canbot.u05.R;

public class LoadingDialogUtils {

        public static Dialog createLoadingDialog(Context context, String msg) {
                LayoutInflater inflater = LayoutInflater.from(context);
                View v = inflater.inflate(R.layout.dialog_loading, null);// 得到加载view
                RelativeLayout layout = (RelativeLayout) v
                        .findViewById(R.id.dialog_loading_view);// 加载布局
                TextView tipTextView = (TextView) v.findViewById(R.id.tipTextView);// 提示文字
                tipTextView.setText(msg);// 设置加载信息

                Dialog loadingDialog = new Dialog(context, R.style.MyDialogStyle);// 创建自定义样式dialog
                loadingDialog.setCancelable(true); // 是否可以按“返回键”消失
                loadingDialog.setCanceledOnTouchOutside(false); // 点击加载框以外的区域
                loadingDialog.setContentView(layout);// 设置布局

                loadingDialog.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
                /**
                 *将显示Dialog的方法封装在这里面
                 */
//                Window window = loadingDialog.getWindow();
//                WindowManager.LayoutParams lp = window.getAttributes();
//                lp.width = WindowManager.LayoutParams.MATCH_PARENT;
//                lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
//                window.setGravity(Gravity.CENTER);
//                window.setAttributes(lp);
//                window.setWindowAnimations(R.style.PopWindowAnimStyle);
                loadingDialog.show();

                return loadingDialog;
        }

        /**
         * 关闭dialog
         * <p>
         * http://blog.csdn.net/qq_21376985
         *
         * @param mDialogUtils
         */
        public static void closeDialog(Dialog mDialogUtils) {
                if (mDialogUtils != null && mDialogUtils.isShowing()) {
                        mDialogUtils.dismiss();
                }
        }

}